define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'change/retreat/index' + location.search,
                    // add_url: 'change/retreat/add',
                    // edit_url: 'change/retreat/edit',
                    // del_url: 'change/retreat/del',
                    // multi_url: 'change/retreat/multi',
                    table: 'sales_retreat',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),class:'retreat_id'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'number', title: __('Number')},
                        {field: 'collectiontime', title: __('Collectiontime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'explain', title: __('Explain')},
                        {field: 'abstract', title: __('Abstract')},
                        {field: 'operator', title: __('Operator')},
                        {field: 'company', title: __('Company')},
                        {field: 'status', title: __('Status')},
                        {field: 'tax', title: __('Tax'), operate:'BETWEEN'},
                        {field: 'salescheckout.number', title: __('Salescheckout.number')},
                        {field: 'salesslip.number', title: __('Salesslip.number')},
                        {field: 'customer.nickname', title: __('Customer.nickname')},
                        {field: 'storehouse.name', title: __('Storehouse.name')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            $('table').on('dblclick','td',function(){
                var retreat_id = $(this).parents('tr').find('.retreat_id').html()
                var url = Config.this_url+'/change/retreat/detail?ids='+retreat_id
                layer.open({
                    type: 2, // 1-在content中写html代码， 2-在content中写src路径
                    area: ['80%', '90%'],
                    title: "退货详情",
                    content: url,
                    // content: Config.this_url+'/purchase/requisition',
                })
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});